package com.itheima.info.manager.service;

import com.itheima.info.manager.dao.StudentDao;
import com.itheima.info.manager.domain.Student;

public class StudentService {
    StudentDao  studentDao = new StudentDao();
    public boolean isExists(String id) {

        Student[] stu = studentDao.findStudent();
        for (int i = 0; i < stu.length; i++) {
            Student student =stu[i];
            if (student !=null&&student.getId().equals(id)){
                return true;
            }
        }
        return false;
    }

    public boolean addStudent(Student stu) {
        return studentDao.addStudent(stu);
    }

    public Student[] findStudent() {
        Student[] stu = studentDao.findStudent();
        boolean flag = false;
        for (int i = 0; i < stu.length; i++) {
            if (stu[i]!=null){
                flag=true;
                break;
            }
        }
        if (flag) {
            return studentDao.findStudent();
        }else {
            return null;
        }
    }

    public void deleteStudent(String delId) {
        studentDao.deleteStudent(delId);
    }

    public void updataStudent(String updataId, Student stu) {
        studentDao.updataStudent(updataId,stu);
    }
}
